/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License Version
 *  3 as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
 *  USA.
 */

#ifndef SHELLTEXTWINDOW_H
#define SHELLTEXTWINDOW_H

#include <QTextEdit>

class QCompleter;

class ShellTextWindow : public QTextEdit
{
    Q_OBJECT
public:
    ShellTextWindow(QWidget *parent = 0);
    ~ShellTextWindow();

    void setCompleter(QCompleter *c);
    QCompleter *completer() const;


    void lineNumberAreaPaintEvent(QPaintEvent *event);
    int lineNumberAreaWidth();

protected:
    void keyPressEvent(QKeyEvent *e);
    void focusInEvent(QFocusEvent *e);
    void resizeEvent(QResizeEvent *event);

private slots:
    void insertCompletion(const QString &completion);

    void updateLineNumberAreaWidth(int newBlockCount);
    void highlightCurrentLine();
    void updateLineNumberArea(const QRect &, int);

private:
    QString textUnderCursor() const;

    QWidget *lineNumberArea;
    QCompleter *c;

};


class LineNumberArea : public QWidget
{
public:
    LineNumberArea(ShellTextWindow *editor) : QWidget(editor) {
        codeEditor = editor;
    }

    QSize sizeHint() const {
        return QSize(codeEditor->lineNumberAreaWidth(), 0);
    }

protected:
    void paintEvent(QPaintEvent *event) {
        codeEditor->lineNumberAreaPaintEvent(event);
    }

private:
    ShellTextWindow *codeEditor;
};

#endif // SHELLTEXTWINDOW_H
